<?php
class C_wakil extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_wakil');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			case 'DEACTIVATE' :
				$this->_deactivate();
				break;
			default :
				$this->load->view('app/v_wakil');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['m_mandor_id'] = nosql_post("m_mandor_id");
		$data['wakil_nama'] = nosql_post("wakil_nama");
		$data['wakil_telpon'] = nosql_post("wakil_telpon");
		echo $this->m_wakil->_list($data);
	}
	
	function _insert(){
		$data = array(
			'm_mandor_id' => $this->input->post('m_mandor_id'), 
			'wakil_nama' => $this->input->post('wakil_nama'), 
			'wakil_telpon' => $this->input->post('wakil_telpon'), 
			  
			'wakil_insert_user'	=>$_SESSION[SESSION_USERID],
			'wakil_insert_date'=> date("Y-m-d h:i:s"));
		$this->m_wakil->_insert($data);
		echo 1;
	}
	
	function _update(){
		$wakil_id = $this->input->post('wakil_id');
		$data = array(
			'm_mandor_id' => $this->input->post('m_mandor_id'), 
			'wakil_nama' => $this->input->post('wakil_nama'), 
			'wakil_telpon' => $this->input->post('wakil_telpon'), 
			
			'wakil_update_user'	=> $_SESSION[SESSION_USERID],
			'wakil_update_date'=> date("Y-m-d h:i:s"));
		$this->m_wakil->_update($data,$wakil_id);
		echo 1;
 	}
	
	function _delete(){
		$wakil_id= $this->input->post('wakil_id');
		$this->m_wakil->_delete($wakil_id);
		echo 1;
	}
	
	function _deactivate(){
		$wakil_id= $this->input->post('wakil_id');
		$data = array(
			'wakil_active' => 'n'
		);
		$this->m_wakil->_deactivate($data,$wakil_id);
		echo 1;
	}
}